package org.game.obj;

import akka.actor.typed.ActorRef;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.common.akka.AkkaContext;
import org.common.akka.message.BaseMsg;
import org.common.mongo.collection.SimpleRoleCollection;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 角色Actor管理器
 */
@Slf4j
@Component
public class RoleManager {

    private final Map<Long, ActorRef<BaseMsg>> roleActorMap = new HashMap<>();

    public ActorRef<BaseMsg> createRoleActor(SimpleRoleCollection simpleRoleCollection, Channel channel) {
        long roleId = simpleRoleCollection.getRoleId();
        ActorRef<BaseMsg> actor = AkkaContext.createActor(RoleActor.create(simpleRoleCollection, channel), String.valueOf(roleId));
        roleActorMap.put(roleId, actor);
        return actor;
    }

    public ActorRef<BaseMsg> getRoleActor(long roleId) {
        return roleActorMap.get(roleId);
    }

}
